# Maintainer: Peltoche <dev@halium.fr>
# Co-maintainer: Andrea Pascal <andrea@anodium.net>
# Co-Maintainer: Deeraurty at github

_realname=lsd
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.5
pkgrel=2
pkgdesc="The next gen ls command (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/lsd-rs/lsd"
msys2_references=(
  'purl: pkg:cargo/lsd'
)
license=("spdx:Apache-2.0")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-pkgconf")
options=('!strip')
depends=()
optdepends=("${MINGW_PACKAGE_PREFIX}-ttf-font-nerd: popular collections such as Font Awesome & fonts such as Hack")
           #'powerline-fonts: powerline symbols for terminals')
source=("https://github.com/lsd-rs/lsd/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('120935c7e98f9b64488fde39987154a6a5b2236cb65ae847917012adf5e122d1')

_env() {
  # Not compatible with libgit2 1.8+
  # export LIBGIT2_NO_VENDOR=1
  export WINAPI_NO_BUNDLED_LIBRARIES=1
  export SHELL_COMPLETIONS_DIR="$PWD/completions"
}

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"

  _env
  cargo build --release --frozen
}

check() {
  cd "${_realname}-${pkgver}"

  # Unset lower-cased envs temp and tmp
  # that points to AppData/Local/Temp
  # to pass
  #   - test_list_almost_all_empty_directory
  #   - test_list_all_empty_directory
  unset temp
  unset tmp

  _env
  cargo test --release --frozen
}

package() {
  cd "${_realname}-${pkgver}"

  _env
  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 completions/_lsd "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_lsd"
  install -Dm644 completions/lsd.bash "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/lsd"
  install -Dm644 completions/lsd.fish "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/lsd.fish"
}
